package com.dgut.hisystem.service.impl;

import com.dgut.hisystem.entity.Patient;
import com.dgut.hisystem.mapper.PatientMapper;
import com.dgut.hisystem.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Date;
import java.util.UUID;

@Service
public class PatientServiceImpl implements PatientService {

    @Resource
    private PatientMapper patientMapper;

    @Override
    public Patient selectID(long id){
        return patientMapper.selectID(id);
    }

    @Override
    public void updateBalance(double money,Patient patient){
        patientMapper.updateBalance(money, patient);
    }

    @Override
    public void insert(Patient patient) {
        long id = Math.abs(UUID.randomUUID().hashCode());
        patient.setBr_card(id);
        if (patient.getBr_birthday() == null) {
            patient.setBr_birthday(new Date(1633425342893L));
        }
        if (patient.getBr_blood() == null) {
            patient.setBr_blood("AB型");
        }
        patientMapper.insert(patient);
    }

    @Override
    public void deleteByYhID(long yh_id) {
        patientMapper.deleteByYhID(yh_id);
    }
}
